package middlewares

import (
	"github.com/gin-gonic/gin"
	uuid "github.com/satori/go.uuid"
)

func UUID() gin.HandlerFunc {

	return func(ctx *gin.Context) {

		serialNumber := ctx.Request.Header.Get("x-serialnumber")
		if serialNumber == "" {
			serialNumber = uuid.NewV4().String()
		}
		ctx.Set("serialNumber", serialNumber)

		ctx.Next()
	}
}
